#!/bin/sh

# install.sh
# This script downloads the skeleton template and applies svn:externals
# to create a modular WordPress installation.

# Set the repository path we're working from:

skel_path='http://wp-core.googlecode.com/svn/trunk/skel'

# Make sure we're in a Subversion project directory.

if [ ! -d .svn ]; then
  echo "This doesn't seem to be a Subversion working copy. Run this script from the root of your project's working copy."
  exit 1
fi

# Make note of the current directory, since we have to work around svn's inability to
# export into the current directory:
current_dir=`pwd`

# Go to a temporary directory:
temp_dir=`mktemp -d -t wpcore`
cd $temp_dir

# Export the template to the temp directory:
svn --non-interactive --trust-server-cert --ignore-externals export https://wp-core.googlecode.com/svn/trunk/skel temp

# rsync the export to the working copy directory:
cd temp
rsync -vaP temp/ $current_dir/

# Go back to the working directory:
cd $current_dir

# Set the properties on the root:

svn propget svn:externals $skel_path | svn propset svn:externals --file=- .
svn propget svn:ignore $skel_path | svn propset svn:ignore --file=- .

# We need to svn add the new stuff:

svn add *

# Set the properties on the wp-content directories:

svn propget svn:externals $skel_path/wp-content | svn propset svn:externals --file=- ./wp-content
svn propget svn:ignore $skel_path/wp-content | svn propset svn:ignore --file=- ./wp-content

svn propget svn:externals $skel_path/wp-content/plugins | svn propset svn:externals --file=- ./wp-content/plugins
svn propget svn:ignore $skel_path/wp-content/plugins | svn propset svn:ignore --file=- ./wp-content/plugins

svn propget svn:externals $skel_path/wp-content/themes | svn propset svn:externals --file=- ./wp-content/themes
svn propget svn:ignore $skel_path/wp-content/themes | svn propset svn:ignore --file=- ./wp-content/themes

# Commit the new stuff (assumes credentials are cached!)

svn --non-interactive --trust-server-cert commit -m "Adding WordPress modular skeleton."

# Update the repository to download all the externals:

svn --non-interactive --trust-server-cert update
